function ajax({
    url,
    method,
    success
}){
    var xhr=new XMLHttpRequest();
    xhr.open("get",url,true);
    xhr.send();
    xhr.onreadystatechange=function(){
        if(xhr.readyState==4 && xhr.status==200){
            var res=JSON.parse(xhr.responseText)
            success(res);
        }
    }
}
//按钮
 window.onload=function(){
     $(".search2").click(function(){
        $(".collection").html("");
        var value=$("input").val();
        console.log(value);
        var url=`http://192.168.4.18:3000/search?keywords=${value}&&type=10`;
        ajax({
            url,
            method:"get",
            success:res=>{
                packaging(res)
            }
        })
     })
 }

 function packaging(res){
    var arr=res.result;
    var arr2=arr.albums;
    var arr3=arr2.slice(0,20)
    console.log(arr3);
    arr3.forEach((item,index)=>{
        var html=`
    <a href="5.1-search.html?id=${item.id}">     
    <div class="song">
        <img src=${item.picUrl}>
        <div class="cover"></div>
    </div>
    <div class="songname">${item.name}</div>
    <div class="songername">${item.artist.name}</div>
    </a>
    `
    $(".collection").append(html);
    })
 }